/*
 * ESTO ES UNA LICENCIA DE PRUEBA
 * EL CODIGO ES DE LIBRE ACCESO PERO ACUERDESE QUE ESTA BAJO LICENCIA
 */
package org.japo.java.matisse.samples;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;




/**
 *
 * @author (c) 2014 - TUTORIALES DE NETBEANS Y JAVA
 */
public class ConvertirDolarEuroAsistido extends javax.swing.JFrame {

    
    
       
    public ConvertirDolarEuroAsistido() {
               

                 initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlPrincipal = new javax.swing.JPanel();
        txfTextoeu = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txfTextodol = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("EuroDolar");
        setCursor(new java.awt.Cursor(java.awt.Cursor.MOVE_CURSOR));

        pnlPrincipal.setBackground(new java.awt.Color(255, 255, 153));
        pnlPrincipal.setBorder(javax.swing.BorderFactory.createMatteBorder(10, 10, 10, 10, new java.awt.Color(255, 153, 0)));
        pnlPrincipal.setCursor(new java.awt.Cursor(java.awt.Cursor.MOVE_CURSOR));

        txfTextoeu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfTextoeuActionPerformed(evt);
            }
        });

        jLabel1.setText("€");

        txfTextodol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfTextodolActionPerformed(evt);
            }
        });

        jLabel2.setText("$");

        javax.swing.GroupLayout pnlPrincipalLayout = new javax.swing.GroupLayout(pnlPrincipal);
        pnlPrincipal.setLayout(pnlPrincipalLayout);
        pnlPrincipalLayout.setHorizontalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addComponent(txfTextoeu, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(txfTextodol, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addContainerGap(182, Short.MAX_VALUE))
        );
        pnlPrincipalLayout.setVerticalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addGap(149, 149, 149)
                .addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfTextoeu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(txfTextodol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addContainerGap(214, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        setSize(new java.awt.Dimension(630, 441));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void txfTextoeuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfTextoeuActionPerformed
         Object o = evt.getSource();

        procesarConversion(o);
    }//GEN-LAST:event_txfTextoeuActionPerformed

    private void txfTextodolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfTextodolActionPerformed
        conversorDoleu();
    }//GEN-LAST:event_txfTextodolActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ConvertirDolarEuroAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ConvertirDolarEuroAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ConvertirDolarEuroAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ConvertirDolarEuroAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ConvertirDolarEuroAsistido().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel pnlPrincipal;
    private javax.swing.JTextField txfTextodol;
    private javax.swing.JTextField txfTextoeu;
    // End of variables declaration//GEN-END:variables

    
    public void procesarConversion(Object o) {

        if (o.equals(txfTextoeu)) {
            conversorEudol();
        } else {
            conversorDoleu();
        }
    }

    private void conversorEudol() {

        try {

            double euro = Double.parseDouble(txfTextoeu.getText());
            double dolar = euro * 1.12;
            String textodol = String.format("%.2f", dolar);
            txfTextodol.setText(textodol);
        } catch (Exception e) {
            txfTextodol.setText("???");
        }

    }

    private void conversorDoleu() {

        try {
            double dolar = Double.parseDouble(txfTextodol.getText());
            double euro = dolar / 1.12;
            String textoeu = String.format("%.2f", euro);
            txfTextoeu.setText(textoeu);
        } catch (Exception e) {
            txfTextoeu.setText("???");
        }
    }
    
}
